﻿//var personInit = function(){
//    $("#personList").datagrid({
//        title: '人员信息',
//        //sortName: 'BusinessEntityID',
//        //sortOrder: 'asc',
//        url:'/Person/GetData',
//        //frozenColumns: [
//        //    { field: 'ck', checkbox: true },
//        //    { field: 'BusinessEntityID',title:'BusinessEntityID' }
//        //],
//        columns: [
//            {field:'PersonType',title:'PersonType'}
//        ]
//    });
//}

//$(function () {
//    //personInit();
//    console.log($("#personList"));
//    $("#personList").datagrid({
//        title: '人员信息',
//        //sortName: 'BusinessEntityID',
//        //sortOrder: 'asc',
//        url: '/Person/GetData',
//        //frozenColumns: [
//        //    { field: 'ck', checkbox: true },
//        //    { field: 'BusinessEntityID',title:'BusinessEntityID' }
//        //],
//        columns: [
//            { field: 'PersonType', title: 'PersonType' }
//        ]
//    });
//})

$(function () {
    //personInit();
    console.log($("#personList"));
    $('#personList').datagrid({
        toolbar: [{
            text: 'append',
            iconCls: 'icon-add',
            handler: function () {
                console.log('append');
            },
        },{
            text:'search',
            handler:function(){
                search();
            }
        }],
        title: '人员信息',
        //sortName: 'BusinessEntityID',
        //sortOrder: 'asc',
        url: '/Person/GetData',
        frozenColumns: [[
            { field: 'ck', checkbox: true },
            { field: 'BusinessEntityID', title: 'BusinessEntityID', sortable: true }
        ]],
        columns: [[
            { field: 'PersonType', title: 'PersonType', rowspan: 2 },
            { field: 'NameStyle', title: 'NameStyle', rowspan: 2 },
            { field: 'Title', title: 'Title', rowspan: 2 },
             { title: 'Name', colspan: 3 },
             { field: 'Suffix', title: 'Suffix',rowspan:2 },
             { field: 'EmailPromotion', title: 'EmailPromotion', rowspan: 2 },
             { field: 'AdditionalContactInfo', title: 'AdditionalContactInfo', rowspan: 2 },
             { field: 'Demographics', title: 'Demographics', rowspan: 2 },
             { field: 'rowguid', title: 'rowguid', rowspan: 2 },
             { field: 'ModifiedDate', title: 'ModifiedDate', rowspan: 2,sortable:true },
        ],[
            { field: 'FirstName', title: 'FirstName' },
            { field: 'MiddleName', title: 'MiddleName' },
            { field: 'LastName', title: 'LastName' },
            
        ]],
        fitColumns:true,
        pagination: true,
        rownumbers: true,
        pageNumber: 1,
        pageSize: 20,

    });

    console.log($('#personList').datagrid('getPager'));

    $('#personList').datagrid('getPager').pagination({

        onSelectPage: function (pPageIndex, pPageSize) {
            console.log("sddjj");
            //改变opts.pageNumber和opts.pageSize的参数值，用于下次查询传给数据层查询指定页码的数据   
            var gridOpts = $('#personList').datagrid('options');
            gridOpts.pageNumber = pPageIndex;
            gridOpts.pageSize = pPageSize;
            //定义查询条件   
            var queryCondition = {  };
            //异步获取数据到javascript对象，入参为查询条件和页码信息   
            var oData = getAjaxData("Person", "GetData", queryCondition, gridOpts);
            //使用loadDate方法加载Dao层返回的数据   
            $('#personList').datagrid('loadData', { "total": oData.page.recordCount, "rows": oData.data });
        }
    });
})

function search() {
    $.ajax({
        url: '/Person/GetData',
        data: { page: 2, row: 20 },
        success: function (data) {
            $('#personList').datagrid('loadData',data);
        }
    });

    
}



